package com.cryptooj.project.model.vo;

import cn.hutool.json.JSONUtil;
import com.cryptooj.project.judge.codesandbox.model.JudgeInfo;
import com.cryptooj.project.model.entity.QuestionSubmit;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;

/**
 *  返回题目提交请求的处理结果
 * */
@Data
public class QuestionSubmitVO implements Serializable {

    private Long id;

    private String language;

    private String code;

    private JudgeInfo judgeInfo;

    private Integer status;

    private Long questionId;

    private Long userId;

    private UserVO userVO;

    private QuestionVO questionVO;

    private Date createTime;

    private Date UpdateTime;

    private static final Long SerialVersionUID = 1L;

    /**
     *  VO包装类转对象
     * */
    public static QuestionSubmit voToObj(QuestionSubmitVO questionSubmitVO){
        if(questionSubmitVO == null){
            return null;
        }
        QuestionSubmit questionSubmit = new QuestionSubmit();
        BeanUtils.copyProperties(questionSubmitVO,questionSubmit);
        JudgeInfo info = questionSubmitVO.getJudgeInfo();
        if(info!=null){
            questionSubmit.setJudgeInfo(JSONUtil.toJsonStr(info));
        }
        return questionSubmit;
    }

    /**
     *  对象转VO包装类
     * */
    public static  QuestionSubmitVO objToVO(QuestionSubmit questionSubmit){
        if(questionSubmit == null){
            return null;
        }
        QuestionSubmitVO questionSubmitVO = new QuestionSubmitVO();
        BeanUtils.copyProperties(questionSubmit,questionSubmitVO);
        String info = questionSubmit.getJudgeInfo();
        questionSubmitVO.setJudgeInfo(JSONUtil.toBean(info,JudgeInfo.class));
        return questionSubmitVO;

    }
}
